﻿using UnityEngine;
using System.Collections;
using DG.Tweening;
public class CameraModel : MonoBehaviour {
    //持续时间
    public float duration = 1f;
    //连个都报警的旋转开关
    public  bool isRotate = false;
    //旋转返回判断开关
    bool isReset;
	// Use this for initialization
	void Start () {
       
	}
	
	// Update is called once per frame
	void Update () {
        if (isRotate)
            RotateCamreaDouble();
	}
    /// <summary>
    /// 两个都报警
    /// </summary>
    public void RotateCamreaDouble()
    {
        if (!isReset)
        {
            this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.Euler(0, 200f, 0f), duration * Time.deltaTime);    //插值旋转:速度由快到慢
            //this.transform.rotation = Quaternion.RotateTowards(this.transform.rotation, Quaternion.Euler(0, 200f, 0f), duration * Time.deltaTime);
            if (Mathf.Abs(transform.eulerAngles.y - 200f) <= 2f)
            {
                isReset = !isReset;
                return;
            }
        }
        else
        {
            this.transform.rotation = Quaternion.Lerp(this.transform.rotation, Quaternion.Euler(0, 150f, 0f), duration * Time.deltaTime);      //平滑旋转：速度平稳
            //this.transform.rotation = Quaternion.RotateTowards(this.transform.rotation, Quaternion.Euler(0, 150f, 0f), duration * Time.deltaTime);
            if (Mathf.Abs(transform.eulerAngles.y - 150f) <= 2f)
            {
                isReset = !isReset;
                return;
            }
        }
    }
    /// <summary>
    /// 看向左箱子
    /// </summary>
    public void LookAtLeftBox()
    {
       this.transform.rotation =   Quaternion.Euler(0, 150f, 0f);
    }
    /// <summary>
    /// 初始化摄像机，没报警的时候用
    /// </summary>
    public void InitCamera()
    {
        this.transform.rotation = Quaternion.Euler(new Vector3(0f, 180f, 0f));
    }
    /// <summary>
    /// 看向右箱子
    /// </summary>
    public void LookAtRightBox()
    {
        this.transform.rotation = Quaternion.Euler(0, 200f, 0f);
    }
}
